package framework.ui.swing;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import org.openems.entity.Key;

import framework.DomainService;
import framework.ui.EmsButtonConnector;
import framework.ui.IButton;
import framework.ui.IButtonListener;

public class SwingButtonWrapper {
	private JButton button;

	public SwingButtonWrapper(Key key, DomainService service) {
		this.button = new JButton();
		initialize(key, service);
	}

	private void initialize(Key key, DomainService service) {
		new EmsButtonConnector(new IButton() {

			@Override
			public void setText(String nextText) {
				button.setText(nextText);
			}

			@Override
			public void setOnAction(final IButtonListener listener) {
				button.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						listener.onClick();
					}
					
				});
			}

			@Override
			public String getText() {
				return button.getText();
			}
			
		}, service, key);
	}
}
